package com.neteast.androidclient.db;

import java.util.ArrayList;
import java.util.HashMap;
import com.neteast.androidclient.contact.domain.Contact;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class AccountDao {
	private MyDBHelp dbHelp;
	private SQLiteDatabase db;
	private Context context;
	
	public AccountDao(Context context) {
		this.context=context;
	}
	
	public void open() {
		dbHelp=new MyDBHelp(context);
		db=dbHelp.getWritableDatabase();
	}
	
	public void close() {
		dbHelp.close();
	}
	
	public String insert(String account) {
		ContentValues values=new ContentValues();
		values.put("account", account);
		return Long.toString(db.insert("accounts", null, values));
	}
	/**
	 * 根据用户id得到数据用户在数据库里的流水号
	 * @param account
	 * @return
	 */
	public String get(String account) {
		Cursor cursor = db.rawQuery("select _id from accounts where account=?", new String[]{account});
		String userId=null;
		if (cursor.moveToFirst()) {
			userId = cursor.getString(0);
			cursor.close();
		}
		return userId;
	}
	/**
	 * 得到所有的userID
	 * @return
	 */
	public ArrayList<String> getAll() {
		Cursor cursor = db.rawQuery("select account from accounts",null);
		ArrayList<String> accounts=null;
		if (cursor.moveToFirst()) {
			accounts=new ArrayList<String>();
			do {
				accounts.add(cursor.getString(0));
			} while (cursor.moveToNext());
		}
		return accounts;
	}
}
